package com.bidv.wcm;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ibm.workplace.wcm.api.Repository;
import com.ibm.workplace.wcm.api.VirtualPortalContext;
import com.ibm.workplace.wcm.api.WCM_API;


/**
 * Servlet implementation class GetListContent
 */
@WebServlet("/GetList")
public class GetList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetList() {
        super();
        // TODO Auto-generated constructor stub
    }
    

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    String responseString = "";
		try {
			//createPrivatePage(request,response);
			//getNavigationSelectionModel(request,response);
			Repository repo = WCM_API.getRepository();
			VirtualPortalContext vctx = repo.generateVPContextFromContextPath(request.getParameter("Context"));
			
			VPList vpA = new VPList();
			
			//vpA.Dir = request.getParameter("Dir");
			
			//vpA.Npp = Integer.parseInt(request.getParameter("Npp"));
			vpA.Npp = 5;
			
			//vpA.PageNum = Integer.parseInt(request.getParameter("PageNum"));
			vpA.PageNum = 1;
			vpA.cp = request.getContextPath();
			
			//vpA.context = request.getParameter("Context");
			
			//vpA.doclib  = request.getParameter("DocLib");
			//vpA.index = request.getParameter("index");
			WCM_API.getRepository().executeInVP(vctx, vpA);
			
			responseString = vpA.Data;
			
		} catch (Exception ex){
			ex.printStackTrace();
		}
		response.setContentType("text/html;charset=utf-8");
		response.getOutputStream().write(responseString.toString().getBytes("UTF-8"));
	}

}
